package com.example.carbon.controller;

import com.example.carbon.Dto.mesSave.MesSaveDto;
import com.example.carbon.Dto.mesSave.Search;
import com.example.carbon.pojo.RestBean;
import com.example.carbon.pojo.mesSave.MesSave;
import com.example.carbon.server.info.MesSaveInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/api/mes")
public class MesSaveController {

    @Resource
    MesSaveInfo mesSaveInfo;

    @GetMapping("/getall")
    public RestBean getAll(){
        if (mesSaveInfo.getAllMesInfo()!=null){
            return RestBean.success(mesSaveInfo.getAllMesInfo());
        }
        return RestBean.failure(500,"获取失败");
    }

    @PostMapping("set")
    public RestBean updateNewInfo(@RequestBody MesSave mesSave){
        if (mesSaveInfo.updateMesInfo(mesSave)){
            return RestBean.success("更新成功");
        }
        return RestBean.failure(500,"更新用户失败");
    }

    @PostMapping("insert")
    public RestBean insertNewInfo(@RequestBody MesSave mesSave){

        if (mesSaveInfo.insertNewMesInfo(mesSave)){
            return RestBean.success("插入数据成功");
        }
        return RestBean.failure(500,"插入数据失败");
    }

    @RequestMapping("/del")
    public RestBean deleteById(int id){
        if (mesSaveInfo.deleteById(id)){
            return RestBean.success("删除成功");
        }
        return RestBean.failure(500,"删除失败");
    }

    @PostMapping("/search")
    public RestBean searchByKey(@RequestBody Search search){
        if (mesSaveInfo.searchMesBykey(search)!=null){
            return RestBean.success(mesSaveInfo.searchMesBykey(search));
        }
        return RestBean.failure(500,"搜索失败");
    }
}
